﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;

using MyDHServer.Compontents;
namespace MyDHServer.Contorls
{
    public abstract class MenuItemBaseControl:SkinControl
    {
        public MenuItemBaseControl()
        {

        }

        public virtual string FileName
        {
            get
            {
                Object state = ViewState["FileName"];
                if (state != null)
                {
                    return (String)state;
                }
                return "Menus.xml";
            }
            set
            {
                ViewState["FileName"] = value;
            }
        }

        public virtual string FileLocation
        {
            get
            {
                string path = Context.Server.MapPath(this.FileName);
                return path;
            }
        }

        protected MenuItemCollection GetMenuItems()
        {
            string path = FileLocation;

            if (path.StartsWith("/") || path.StartsWith("~"))
            {
                path = Context.Server.MapPath(path);
            }

            // TODO 等缓存类设计完后这里修改为从缓存读取
            MenuItemCollection mc = (MenuItemCollection)Serializer.ConvertFileToObject(path, typeof(MenuItemCollection));

            return mc;
        }
    }
}
